package example.simple_mindmap.common.domain.po;

import com.fasterxml.jackson.annotation.JsonInclude;
import example.simple_mindmap.common.enums.ResultCode;
import lombok.Data;

/**
 * @BelongsProject: 0.forum_system
 * @BelongsPackage: com.example.forum_system.common
 * @Author : 游在海里的鱼
 * @CreateTime : 2023-11-03  14:31
 * @Version : 1.0
 * @Description : TODO
 */
@Data
public class Result<T> {
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private int code;
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private String message;
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private T data;

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**-----------------------------------类---方---法-------------------------------------------------------------------
     * @Desc  : 成功情况下的返回方法
     * @Param : [chainData]
     * @Return: com.example.forum_system.common.Result<T>
    **/
    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }
    public static Result success(){
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),null);
    }

    /**-----------------------------------类---方---法-------------------------------------------------------------------
     * @Desc  : 失败情况下的返回方法
     * @Param : [resultCode, chainData]
     * @Return: com.example.forum_system.common.Result<T>
    **/
    public static <T> Result<T> failed(ResultCode resultCode,T data){
        return new Result<T>(resultCode.getCode(),resultCode.getMessage(),data);
    }
    public static Result failed(ResultCode resultCode){
        return new Result(resultCode.getCode(),resultCode.getMessage(),null);
    }


}
